package com.zq.it.action.admin;

import java.util.List;

import javax.annotation.Resource;

import com.zq.it.action.BaseAction;
import com.zq.it.pojo.CourseManage;
import com.zq.it.service.admin.CourseManageService;
import com.zq.it.tool.Constant;
import com.zq.it.tool.FileName;
import com.zq.it.tool.FileType;
import com.zq.it.tool.HeadTitle;

import net.sf.json.JSONArray;

public class CourseManageAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	@Resource
	private CourseManageService courseManageService;

	private CourseManage courseManage = null;
	private int[] courseManageGroupId;
	// 查询关联条件
	public void searchParam() {
		print(toJSON(courseManageService.getParam()).toString(), "UTF-8",
				"TEXT/JSON");
	}
	public void searchCourseManageListBySQL() {
		List list = courseManageService.getCourseManageListBySQL(courseManage);
		uploadList(com.zq.it.tool.EtyLsName.CSM_LS.name(), list);
		print(JSONArray.fromObject(list,Constant.getJcf(new String[]{"teacher", "address","course", "tclass"})).toString(), "UTF-8", "APPLICATION/JSON");
	}

	public void deleteCourseManageGroupId() {
		courseManageService.removeAllCourseManage(courseManageGroupId);
		print("已删除" + courseManageGroupId.length + "条记录！", "UTF-8",
				"text/html");
	}
	public void addCourseManagePo() {
		courseManageService.addCourseManage(courseManage);
		print("<script>parent.closeWindow('已添加');</script>", "UTF-8",
				"text/html");
	}
	public void modifyCourseManagePo() {
		// System.out.println(courseManage.getTeacher());
		courseManageService.renewalCourseManage(courseManage);
		print("<script>parent.closeWindow('已修改！');</script>", "UTF-8",
				"text/html");
	}
	public void importCourseManageList() {
		String msgStr = "";
		List<CourseManage> list = courseManageService
				.importCourseManageList(getUpload());
		if (list.size() > 0) {
			getRequest().getSession().setAttribute("existCourseManageList",
					list);
			msgStr = "existList";
		} else {
			msgStr = "已导入成功!";
		}
		print("<script>parent.importBackResult('" + msgStr
				+ "','webpage/adminpage/courseManageService/existCourseManage.jsp');</script>",
				"UTF-8", "TEXT/HTML");
	}
	public void exportCourseManageList() {
		download(
				courseManageService.exportCourseManageList(
						HeadTitle.CN_CMAGHEAD.getArray(),
						(List<CourseManage>) getHttpSession().getAttribute(
								com.zq.it.tool.EtyLsName.CSM_LS.name())),
				FileName.CMAG_LIST_NAME.toString() + FileType.XLSX);
	}

	public CourseManage getCourseManage() {
		return courseManage;
	}
	public void setCourseManage(CourseManage courseManage) {
		this.courseManage = courseManage;
	}
	public int[] getCourseManageGroupId() {
		return courseManageGroupId;
	}
	public void setCourseManageGroupId(int[] courseManageGroupId) {
		this.courseManageGroupId = courseManageGroupId;
	}
	/*
	 * public void deleteCourseManage(){
	 * courseManageService.removeCourseManage(courseManage); }
	 */

}
